package com.dirk.happie.adapters;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.dirk.happie.R;
import com.dirk.happie.beans.ArticleBean;
import com.dirk.happie.beans.ArticleSize;
import com.dirk.happie.utils.Common;

public class ArticleSizeListAdapter extends ArrayAdapter<ArticleBean> {

	Context context;
	int layoutResourceId;
	ArticleSize data[] = null;

	public ArticleSizeListAdapter(Context context, int layoutResourceId,
			ArrayList<ArticleBean> data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ProductTypeHolder holder = null;

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new ProductTypeHolder();
			holder.txtSize = (TextView) row.findViewById(R.id.txtSize);
			holder.price = (TextView) row.findViewById(R.id.txtPrice);

			row.setTag(holder);
		} else {
			holder = (ProductTypeHolder) row.getTag();
		}

		ArticleBean product = getItem(position);
		holder.txtSize.setText(product.getArticleSize());
		holder.price.setText(getString(R.string.currency) + " " + Common.getPrice(product.getArticlePrice()));

		return row;
	}

	private String getString(int resId) {
		
		return context.getString(resId);
	}

	static class ProductTypeHolder {
		TextView txtSize;
		TextView price;

	}
	
	public void clearCaches(){
		
	}
}